<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">页面导航</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form layui-form-pane">
                        <input type="hidden" name="id" value="{:array_get($info,'id')}">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>位置</label>
                            <div class="layui-input-block">
                                <select name="tab">
                                    {volist name="tab_list" id="v"}
                                    <option value="{$key}" {eq name=":array_get($info,'tab',1)" value="$key" }selected{/eq}>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" value="{:array_get($info,'title')}" lay-verify="required"
                                       placeholder="请输入标题"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>标图</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn attachment-upload-images" data-input="image"
                                            data-amount="1">上传图片
                                    </button>
                                    <div class="layui-inline layui-word-aux"> 最佳尺寸：240px*240px</div>
                                    <div class="layui-upload-list echo-attachment-image-list" id="image">
                                        {notempty name="info.image"}
                                        <div>
                                            <input type="hidden" name="image" value="{:array_get($info,'image')}">
                                            <img src="{:array_get($info,'image')}">
                                        </div>
                                        {/notempty}
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">跳转链接</label>
                            <div class="layui-input-block">
                                <input type="text" name="url" value="{:array_get($info,'url')}"
                                       placeholder="请输入跳转链接"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>状态</label>
                            <div class="layui-input-block">
                                {volist name="status_list" id="v"}
                                <input type="radio" name="status" value="{$key}" title="{$v}" {eq name=":array_get($info,'status',1)" value="$key" }checked{/eq}>
                                {/volist}
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>排序</label>
                            <div class="layui-input-block">
                                <input type="text" name="priority" value="{:array_get($info,'priority',255)}"
                                       lay-verify="required" placeholder="请输入排序值（倒序，值越大越靠前）"
                                       autocomplete="off" class="layui-input">
                                <div class="layui-form-mid layui-word-aux">倒序，值越大越靠前</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="button" lay-submit lay-filter="{$lay_btn}" value="确认提交" class="layui-btn">
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['index', 'form', 'upload'], function () {
        const $ = layui.$;
        const admin = layui.admin;
        const form = layui.form;
        const upload = layui.upload;
        form.render();

        form.on('submit({$lay_btn})', function (obj) {
            var index = parent.layer.getFrameIndex(window.name);
            admin.req({
                url: "{:url('navigation/editNavigation')}",
                type: 'post',
                data: obj.field,
                done: function (res) {
                    layer.msg("提交成功", {icon: 1});
                    parent.layui.table.reload('lay-navigation-index-table'); //重载表格
                    parent.layer.close(index);
                }
            });
        });

        $('.echo-attachment-image-list').on('click', '.attachmentdel', function () {
            $(this).parent().remove();
        });

        let upload_input = '';
        let upload_amount = '';
        upload.render({
            elem: '.attachment-upload-images',
            url: "{:url('upload/image')}",
            accept: 'images',
            exits: 'jpg|png|jpeg',
            acceptMime: 'image/*',
            size: 2048,
            number: 1,
            method: 'post',
            before: function (obj) {
                const item = this.item;
                upload_input = $(item).data('input');
                upload_amount = $(item).data('amount');
                layer.load();
            },
            done: function (res, index, upload) {
                layer.closeAll('loading');
                let html = "";
                if (upload_amount == 1) {
                    html += '<div> <input type="hidden" name="' + upload_input + '" value="' + res.data.src + '"> ';
                    html += '<img src="' + res.data.src + '"></div>';
                    $("#" + upload_input).html(html);
                } else {
                    html += '<div> <input type="hidden" name="' + upload_input + '[]" value="' + res.data.src + '"> ';
                    html += '<img src="' + res.data.src +
                        '"> <button type="button" class="attachmentdel layui-btn layui-btn-primary layui-btn-xs layui-btn-fluid">删除</button></div>';
                    $("#" + upload_input).append(html);
                }
            },
            error: function (index, upload) {
                layer.closeAll('loading');
            }
        });

    });
</script>
